package day05;

import java.util.Stack;

/**
 *代码随想录 用栈实现队列
 */
public class MyQueue<T> {

    Stack<T> stackIn;
    Stack<T> stackOut;

    public MyQueue() {
        stackIn = new Stack<>();
        stackOut = new Stack<>();
    }

    public void push(T x) {
        stackIn.push(x);
    }

    public T pop() {
        dumpstackIn();
        return stackOut.pop();
    }

    public T peek() {
        dumpstackIn();
        return stackOut.peek();
    }

    public boolean isEmpty() {
        return stackIn.isEmpty() && stackOut.isEmpty();
    }

    private void dumpstackIn(){
        if (!stackOut.isEmpty()) return;
        while (!stackIn.isEmpty()){
            stackOut.push(stackIn.pop());
        }
    }
}
